package net.entelijan.cobean.examples.showcase.config.text;

import static org.junit.Assert.assertEquals;
import net.entelijan.cobean.examples.showcase.ShowcaseTestFrame;
import net.entelijan.cobean.examples.showcase.config.toggle.ConfigBookAuthorTogglePanel;
import net.entelijan.cobean.examples.showcase.config.toggle.ConfigBookAuthorToggleShowcase;
import net.entelijan.cobean.examples.util.ExamplesUtil;
import net.entelijan.testutil.CobeanTestUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.fest.swing.fixture.FrameFixture;
import org.fest.swing.fixture.JCheckBoxFixture;
import org.junit.Test;

public class ConfigBookAuthorToggleFestTestCase {

	@SuppressWarnings("unused")
	private static Log log = LogFactory
			.getLog(ConfigBookAuthorToggleFestTestCase.class);

	// @SuppressWarnings("unused")
	// public void test() {
	// ConfigBookAuthorTogglePanel panel = new ConfigBookAuthorTogglePanel();
	// CobeanTestUtil.setComponentNamesFromPropertyNames(panel);
	// ShowcaseTestFrame frame = new ShowcaseTestFrame(panel);
	// FrameFixture frameFix = new FrameFixture(frame);
	// try {
	// frameFix.show();
	// ConfigBookAuthorToggleShowcase sc = new ConfigBookAuthorToggleShowcase();
	// sc.setDao(ExamplesUtil.createTestDao());
	// JTextComponentFixture failureTextBox = frameFix
	// .textBox("failureTextField");
	// JTextComponentFixture titleTextBox = frameFix
	// .textBox("titleTextField");
	// JTextComponentFixture subtitleTextBox = frameFix
	// .textBox("subtitleTextField");
	// JTextComponentFixture yearTextBox = frameFix
	// .textBox("yearTextField");
	// JTextComponentFixture authorNameTextBox = frameFix
	// .textBox("authorNameTextField");
	// JTextComponentFixture authorBirthdayTextBox = frameFix
	// .textBox("authorBirthdayTextField");
	// JCheckBoxFixture translationCheckBox = frameFix
	// .checkBox("translationCheckBox");
	//
	// sc.init(panel);
	// pause(100);
	//
	// } finally {
	// frameFix.cleanUp();
	// }
	//
	// }

	@Test
	public void test01() {
		ConfigBookAuthorTogglePanel panel = new ConfigBookAuthorTogglePanel();
		CobeanTestUtil.setComponentNamesFromPropertyNames(panel);
		ShowcaseTestFrame frame = new ShowcaseTestFrame(panel);
		FrameFixture frameFix = new FrameFixture(frame);
		try {
			frameFix.show();
			ConfigBookAuthorToggleShowcase sc = new ConfigBookAuthorToggleShowcase();
			sc.setService(ExamplesUtil.createTestService());
			JCheckBoxFixture translationCheckBox = frameFix
					.checkBox("translationCheckBox");

			sc.init(panel);
			pause(100);

			assertEquals(false, sc.getBook().getTranslation());
			translationCheckBox.requireNotSelected();

			translationCheckBox.check();
			assertEquals(true, sc.getBook().getTranslation());

			sc.getBook().setTranslation(false);
			pause(100);
			translationCheckBox.requireNotSelected();
			assertEquals(false, sc.getBook().getTranslation());

		} finally {
			frameFix.cleanUp();
		}

	}

	private synchronized void pause(int timeMs) {
		try {
			wait(timeMs);
		} catch (InterruptedException e) {
			// Do not mind
		}

	}

}
